package com.tz.dream.architect.mvp.framework.support.viewstate.activity;

import com.tz.dream.architect.mvp.framework.MvpActivity;
import com.tz.dream.architect.mvp.framework.MvpPresenter;
import com.tz.dream.architect.mvp.framework.MvpView;
import com.tz.dream.architect.mvp.framework.support.ActivityMvpDelegate;
import com.tz.dream.architect.mvp.framework.support.viewstate.MvpViewStateDelegateCallback;
import com.tz.dream.architect.mvp.framework.support.viewstate.ViewState;

/**
 * 作者: Dream on 2018/4/1 20:57
 * QQ:510278658
 * E-mail:510278658@qq.com
 */

//代理一：针对于生命周期->代理对象(持有目标对象引用)
//代理二：针对ViewState缓存->目标对象

///备忘录模式->创建备忘录角色->创建备忘录->MvpViewStateActivity
public abstract class MvpViewStateActivity<V extends MvpView, P extends MvpPresenter<V>, VS extends ViewState<V>> extends MvpActivity<V, P>
    implements MvpViewStateDelegateCallback<V, P, VS> {

    private VS viewState;
    //是否已经恢复状态
    protected boolean restoringViewState = false;

    @Override
    public ActivityMvpDelegate<V, P> getMvpDelegate() {
        if (mvpDelegate == null){
            mvpDelegate = new ActivityMvpViewStateDelegateImpl<V, P, VS>(this, this, true);
        }
        return super.getMvpDelegate();
    }

    @Override
    public VS getViewState() {
        return viewState;
    }

    @Override
    public void setViewState(VS viewState) {
        this.viewState = viewState;
    }

    @Override
    public void setRestoringViewState(boolean restoringViewState) {
        this.restoringViewState = restoringViewState;
    }

    @Override
    public boolean isRestoringViewState() {
        return restoringViewState;
    }

    @Override
    public void onViewStateInstanceRestored(boolean instanceStateRetained) {

    }

}
